package com.youdianda.controller.sys;



import com.youdianda.dto.SysUserDTO;
import com.youdianda.dto.SysUserPageDTO;
import com.youdianda.result.Result;
import com.youdianda.service.SysUserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@Slf4j
@RequestMapping("/sys_user")
public class SysUserController {

    @Autowired
    private SysUserService sysUserService;

    /**
     * 分页条件查询系统用户列表
     * @param sysUserPageDTO
     * @return
     */
    @GetMapping("/list")
    public Result listSysUserPage(SysUserPageDTO sysUserPageDTO) {
        log.info("分页条件查询系统用户列表 {}", sysUserPageDTO);
        return sysUserService.listSysUserPage(sysUserPageDTO);
    }

    /**
     * 根据id删除系统用户
     * @param id
     * @return
     */
    @GetMapping("/del")
    public Result deleteSysUserById(String id) {
        log.info("根据id删除系统用户: id = {}", id);
        return sysUserService.deleteRoleById(id);
    }

    /**
     * 系统用户添加
     * @param sysUserDTO
     * @return
     */
    @PostMapping("/add")
    public Result addSysUser(@RequestBody SysUserDTO sysUserDTO) {
        log.info("系统用户添加: {}", sysUserDTO);
        return sysUserService.addSysUser(sysUserDTO);
    }

    /**
     * 根据id查询系统用户详情
     * @return
     */
    @GetMapping("/rowInfo")
    public Result getSysUserById(String id) {
        log.info("根据id查询系统用户详情：id = {}", id);
        return sysUserService.getSysUserById(id);
    }

    /**
     * 系统用户修改
     * @param sysUserDTO
     * @return
     */
    @PostMapping("/update")
    public Result updateSysUser(@RequestBody SysUserDTO sysUserDTO) {
        log.info("系统用户修改：{}", sysUserDTO);
        return sysUserService.updateSysUser(sysUserDTO);
    }
}
